﻿namespace com.stifel.BranchMgmt
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using com.stifel.Extensions.StringExtensions;

    using com.stifel.BranchMgmtDao;

    public partial class BranchMgmtSelectUserControl : UserControl
    {
        #region Methods

        protected void Page_Load( object sender, EventArgs e )
        {
        }

        protected void uiBranchId_Activate( object sender, EventArgs e )
        {
        }

        protected void uiBranchId_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiBranchUnit_Activate( object sender, EventArgs e )
        {
        }

        protected void uiBranchUnit_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiBroadcastIp_Activate( object sender, EventArgs e )
        {
        }

        protected void uiBroadcastIp_Deactivate( object sender, EventArgs e )
        {
        }

        /// <summary>
        /// Initiates the search
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void uiBtnSearch_Click( object sender, EventArgs e )
        {
            List<StifelBranchInfo> l = new List<StifelBranchInfo>( );

            // from the active view get the programmatic identifier and compare with the command arguments of each navigation button to determine the search method requested
            View v = uiView.GetActiveView( );

            if ( uiBtnBranchId.CommandArgument.Equals( v.ID ) )
            {
                int branchId = uiTbBranchId.Text.ToInt32( );
                l = getBranchsByBranchId( branchId );
                loadResults( l );
            }
            else if ( uiBtnBranchUnit.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByBranchUnit( ); // TODO
            }
            else if ( uiBtnBroadcastIp.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByBroadcastIp( ); // TODO
            }
            else if ( uiBtnCheckCode.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByCheckCode( ); // TODO
            }
            else if ( uiBtnDestCode.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByDestCode( ); // TODO
            }
            else if ( uiBtnOrg.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByOrg( ); // TODO
            }
            else if ( uiBtnPriceServer.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByPriceServer( ); // TODO
            }
            else if ( uiBtnSiteId.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsBySiteId( ); // TODO
            }
            else if ( uiBtnSpeedDial.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsBySpeedDial( ); // TODO
            }
            else if ( uiBtnThompsonId.CommandArgument.Equals( v.ID ) )
            {
                int thompsonId = uiTbThomsonId.Text.ToInt32( );
                l = getBranchsByThompsonId( thompsonId );
                loadResults( l );
            }
            else if ( uiBtnWireCode.CommandArgument.Equals( v.ID ) )
            {
                l = getBranchsByWireCode( ); // TODO
            }
        }

        protected void uiCheckCode_Activate( object sender, EventArgs e )
        {
        }

        protected void uiCheckCode_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiDestCode_Activate( object sender, EventArgs e )
        {
        }

        protected void uiDestCode_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiNavigationTab_Click( object sender, EventArgs e )
        {
            Button button = sender as Button;
            navigateToSelectedView( button );
        }

        protected void uiOrg_Activate( object sender, EventArgs e )
        {
        }

        protected void uiOrg_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiPriceServer_Activate( object sender, EventArgs e )
        {
        }

        protected void uiPriceServer_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiResults_ItemCommand( object source, RepeaterCommandEventArgs e )
        {
        }

        protected void uiResults_ItemDataBound( object sender, RepeaterItemEventArgs e )
        {
        }

        protected void uiSiteId_Activate( object sender, EventArgs e )
        {
        }

        protected void uiSiteId_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiSpeedDial_Activate( object sender, EventArgs e )
        {
        }

        protected void uiSpeedDial_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiThompsonId_Activate( object sender, EventArgs e )
        {
        }

        protected void uiThompsonId_Deactivate( object sender, EventArgs e )
        {
        }

        protected void uiWireCode_Activate( object sender, EventArgs e )
        {
        }

        protected void uiWireCode_Deactivate( object sender, EventArgs e )
        {
        }

        void loadResults( List<StifelBranchInfo> values )
        {
            if (values==null || values.Count <=0) return;

            uiResults.Visible = true;
            uiSearch.Visible = false;
            uiResults_Repeater.DataSource = values;
            uiResults_Repeater.DataBind( );
        }

        #endregion Methods
    }
}